<template>
  <link rel="stylesheet" href="/assets/css/poster.css" />

  <div class="headerbox">
    <div class="header">
      <div class="headerL">
        <a @click="proxy.$router.go(-1)" class="goback"
          ><img src="/assets/images/goback.png"
        /></a>
      </div>
      <div class="headerC">
        <p>分销信息</p>
      </div>
    </div>
  </div>
  <div class="clear"></div>
  <div class="h50"></div>
  <div>
    <div class="content">
      <div class="poster">
        <img id="poster" :src="poster" alt="点击按钮重新生成海报" />
      </div>

      <div class="link">
        <input
          type="text"
          placeholder="普通输入框"
          readonly
          id="url"
          v-model="url"
        />
        <van-button
        style="width: 28%"
          block
          type="primary"
          color="linear-gradient(160deg, #0093E9 0%, #80D0C7 100%)"
          @click="copyPath"
        >
        点击复制
        </van-button>
      </div>

      <div style="width: 40%; margin: 20px auto">
        <van-button
          round
          block
          type="primary"
          color="linear-gradient(160deg, #0093E9 0%, #80D0C7 100%)"
          @click="newPoster"
        >
          重新生成海报
        </van-button>
      </div>
    </div>
  </div>
</template>
<script setup>
onMounted(() => {
  newPoster();
});

const { proxy } = getCurrentInstance();

const poster = ref();
const url = ref();

const newPoster = async () => {
  var business = proxy.$cookies.get("business");

  var params = {
    id: business.id,
    mobile: business.mobile,
    avatar: business.avatar,
    poster: business.poster,
  };

  var result = await proxy.$POST({
    url: "business/retail",
    params: params,
  });
  // /http://www.fast.com/uploads/qrcode/1718950275.png
  if (result.code) {
    poster.value = result.data.domain + result.data.poster;
    url.value = result.data.url;

    business.poster = result.data.poster;
    proxy.$cookies.set("business", business);
  } else {
    proxy.$fail(result.msg);
  }
};

const Back = () => {};
//复制海报连接
const copyPath = () => {
  var url = document.getElementById("url");

  url.select();

  document.execCommand("copy", false);
};
</script>